﻿using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
//using WPFDevelopers.BasicControls.ExampleViews;
using WPFDevelopers.BasicControls.ExampleViews;
//using WPFDevelopers.BasicControls.ExampleViews.DrawerMenu;
//using WPFDevelopers.BasicControls.ExampleViews.NumberCard;
//using WPFDevelopers.BasicControls.ExampleViews.Passwrod;
using WPFDevelopers.BasicControls.Helpers;
using WPFDevelopers.BasicControls.Models;

namespace WPFDevelopers.BasicControls.ViewModels
{
    public class MainVM : ViewModelBase
    {

        /// <summary>
        /// 
        /// </summary>
        private ObservableCollection<ListBoxItem> _navigateMenuModelList;

        public ObservableCollection<ListBoxItem> NavigateMenuModelList
        {
            get { return _navigateMenuModelList; }
            set { _navigateMenuModelList = value; }
        }


        private NavigateMenuModel _navigateMenuItem;
        /// <summary>
        /// 当前选中的导航菜单模型
        /// </summary>
        public NavigateMenuModel NavigateMenuItem
        {
            get { return _navigateMenuItem; }
            set
            {
                _navigateMenuItem = value;
                this.NotifyPropertyChange("NavigateMenuItem");
            }
        }

        private object _controlPanel;
        /// <summary>
        /// 更换右侧面板
        /// </summary>
        public object ControlPanel
        {
            get { return _controlPanel; }
            set
            {
                _controlPanel = value;
                this.NotifyPropertyChange("ControlPanel");
            }
        }
        public MainVM()
        {

            NavigateMenuModelList = new ObservableCollection<ListBoxItem>();
            foreach (MenuEnum menuEnum in Enum.GetValues(typeof(MenuEnum)))
            {
                NavigateMenuModelList.Add(new ListBoxItem { Content = menuEnum.ToString() });
            }
            NavigateMenuModelList.Add(new ListBoxItem { Content = "持续更新中" });
            ControlPanel = new BasicControlsExample();
        }
        public ICommand ViewLoaded => new RelayCommand(obj =>
        {


        });

        /// <summary>
        /// 菜单选择变化命令
        /// </summary>
        public ICommand MenuSelectionChangedCommand => new RelayCommand(obj =>
        {
            if (obj == null) return;
            //var model = obj as NavigateMenuModel;
            //MenuItemSelection(model.Name);
            var model = obj as ListBoxItem;
            this.MenuItemSelection(model.Content.ToString());
        });

        public ICommand CloseCommand => new RelayCommand(obj =>
        {
            //Environment.Exit(0);
            Application.Current.MainWindow.Close();
        });


        void MenuItemSelection(string _menuName)
        {
            MenuEnum flag;
            if (!Enum.TryParse<MenuEnum>(_menuName, true, out flag))
                return;
            var menuEnum = (MenuEnum)Enum.Parse(typeof(MenuEnum), _menuName, true);
            switch (menuEnum)
            {
                case MenuEnum.ButtonExample:
                    ControlPanel = new ButtonExample();
                    break;

                case MenuEnum.LoadingExample:
                    ControlPanel = new LoadingExample();
                    break;

                case MenuEnum.MessageBoxExample:
                    ControlPanel = new MessageBoxExample();
                    break;   

                case MenuEnum.DataGridExample:
                    ControlPanel = new DataGridExample();
                    break;   
                case MenuEnum.ListViewExample:
                    ControlPanel = new ListViewExample();
                    break;   
                case MenuEnum.ListBoxExample:
                    ControlPanel = new ListBoxExample();
                    break;

                case MenuEnum.ThemeExample:
                    ControlPanel = new ThemeExample();
                    break;    

                case MenuEnum.TreeViewExample:
                    ControlPanel = new TreeViewExample();
                    break;  

                case MenuEnum.ExpanderExample:
                    ControlPanel = new ExpanderExample();
                    break;

                case MenuEnum.GroupBoxExample:
                    ControlPanel = new GroupBoxExample();
                    break;

                case MenuEnum.TabControlExample:
                    ControlPanel = new TabControlExample();
                    break;

                case MenuEnum.BasicControls:
                    ControlPanel = new BasicControlsExample();
                    break;

                default:
                    break;
            }
        }

    }
}
